package com.yunxi.service.sap.dubbo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yunxi.baseDataToHub.pojo.sap.*;
import com.yunxi.eai.pojo.sap.VehiclePriceVo;
import com.yunxi.baseDataToHub.service.sap.SapDubboService;
import com.yunxi.core.base.Constant;
import com.yunxi.core.util.HttpUtil;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.model.eai.EaiLog;
import com.yunxi.rocketmq.producer.EaiLogsProducer;
import com.yunxi.service.ReturnResultMsg;
import com.yunxi.tech.pojo.PmsPartnerReqVO;
import com.yunxi.tech.service.IamBaseDubboService;
import com.yunxi.tech.service.IamPartnerDubboService;
import org.apache.commons.lang3.StringUtils;
import org.dozer.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.*;

/**
 * Created by Administrator on 2019/5/23.
 */
/*@com.alibaba.dubbo.config.annotation.Service(version = "${demo.service.version}",
        application = "${dubbo.application.id}",
        protocol = "${dubbo.protocol.id}",
        registry = "${dubbo.registry.id}"
)*/
public class SapDubboServiceImpl implements SapDubboService {
    protected static final Logger LOGGER = LoggerFactory.getLogger(SapDubboServiceImpl.class);
    /*    @Autowired
        @Qualifier("sapBankServiceImpl")
        SapBankService sapBankService;
        @Autowired
        @Qualifier("sapPartnerServiceImpl")
        SapPartnerService sapPartnerService;*/
    @Autowired
    private EaiLogsProducer eaiLogsProducer;
    @Value("${esb.switch}")
    private String esbSwitch;
    @Value("${PMSPUB.URL}")
    private String PMSPUB_URL;
    @Value("${SAP.URL}")
    private String SAP_URL;
    @Value("${SAP.PRICE.COUNT.URL}")
    private String SAP_PRICE_COUNT_URL;
    @Autowired
    IamPartnerDubboService iamPartnerDubboServiceImpl;
    @Autowired
    private Mapper dozerMapper;
    @Override
    public ApiResult savePartnerInfoToSap(PartnerInfoVO partnerInfoVO) throws Exception {
       if("2".equals(partnerInfoVO.getPartnerType())){
           partnerInfoVO.setPstlz(partnerInfoVO.getPostCode());
           partnerInfoVO.setVkorg("AS52");//销售组织
       }
        partnerInfoVO.setCounc("CN");
        if (!StringUtils.isNotEmpty(partnerInfoVO.getBukrs())){
            partnerInfoVO.setBukrs("AS10");//公司代码
        }
        String partnerInfo = JSONObject.toJSONString(partnerInfoVO);
        ApiResult apiResult=null;
        EaiLog eaiLog=new EaiLog();
        eaiLog.setPmsEaiContent(partnerInfo);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送渠道主数据给SAP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.SAP_PAR);
        if (esbSwitch.equals("false")) {
            return ResponseUtil.ok();
        }
        try {
            Map map = HttpUtil.sendPost(partnerInfo, Constant.SAP_PAR, Constant.PMS, PMSPUB_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(PMSPUB_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag = String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")) {//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_FAIL,"["+Constant.SAP_PAR+"]");
            } else {
                apiResult = ResponseUtil.ok();
            }
        } catch (Exception e) {
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(), e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EXP,"["+Constant.SAP_PAR+"]");
        }
        try {
            if (partnerInfoVO.getPartnerType().equals("2")){
                PmsPartnerReqVO var1 = dozerMapper.map(partnerInfoVO, PmsPartnerReqVO.class);
                ApiResult upsResult = iamPartnerDubboServiceImpl.savePartner(var1);
                if (upsResult.getCode()!=200){
                    eaiLog.setDisposeStatus(3);
                }
            }
        }catch (Exception e){
            //调用UPS系统失败
            eaiLog.setDisposeStatus(3);
            LOGGER.error(e.getMessage(), e);
            LOGGER.error("调用UPS系统失败===========");
        }
        try {
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        }catch (Exception e){
            LOGGER.error(e.getMessage(),e);
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EAI,"["+Constant.SAP_PAR+"]");
        }
        return apiResult;
    }

    /**
     * 价格试算
     * @param vehiclePriceCountVo
     * @return
     * @throws Exception
     */
    @Override
    public ApiResult sendVehiclePriceCountToSap(VehiclePriceCountVo vehiclePriceCountVo) throws Exception {
        String vehiclePrice = JSONObject.toJSONString(vehiclePriceCountVo);
        ApiResult apiResult=null;
        EaiLog eaiLog=new EaiLog();
        eaiLog.setPmsEaiContent(vehiclePrice);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送价格试算数据给SAP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.SAP_VEHICLE_PRICE_COUNT);
        if (esbSwitch.equals("false")) {
            return ResponseUtil.ok(ReturnResultMsg.getVehiclePriceCountMsg());
        }
        try {
            Map map = HttpUtil.sendPost(vehiclePrice, Constant.SAP_VEHICLE_PRICE_COUNT, Constant.PMS, SAP_PRICE_COUNT_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(SAP_PRICE_COUNT_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            // jsonObject.get("statusFlag");
            String statusFlag = String.valueOf(jsonObject.get("statusFlag"));
            //Map<String, Object> headerMap = BeanTools.objectToMap(object);
            // String statusFlag=String.valueOf(headerMap.get("statusFlag"));
            if (statusFlag.equals("0")) {//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_FAIL,"["+Constant.SAP_VEHICLE_PRICE_COUNT+"]");
            } else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (String.valueOf(jsonResponse.get("code")).equals("E")) {
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_ERR,"["+Constant.SAP_VEHICLE_PRICE_COUNT+"]"+String.valueOf(jsonResponse.get("zmess")));
                } else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        } catch (Exception e) {
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(), e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EXP,"["+Constant.SAP_VEHICLE_PRICE_COUNT+"]");
        }
        //Message message = new Message(rocketConfig.getEaiLogTopic(), "eaiLog",(JSONObject.toJSONString(eaiLog)).getBytes() );
        try {
            //   SendResult send = eaiLogProducer.getProducer().send(message);
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        }catch (Exception e){
            LOGGER.error(e.getMessage(),e);
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EAI,"["+Constant.SAP_VEHICLE_PRICE_COUNT+"]");
        }
        return apiResult;
    }

    /**
     * 批售订单
     * @param vehicleBatchOrderVO
     * @return
     * @throws Exception
     */
    @Override
    public ApiResult sendVehicleBatchOrderToSap(VehicleBatchOrderVO vehicleBatchOrderVO) throws Exception {
        //  vehicleBatchOrderVO.setCashcheck("N");
        vehicleBatchOrderVO.setLgort("VW01");
        String vehicleBatchOrder = JSONObject.toJSONString(vehicleBatchOrderVO);
        ApiResult apiResult=null;
        EaiLog eaiLog=new EaiLog();
        eaiLog.setPmsEaiContent(vehicleBatchOrder);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送批售单给SAP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.SAP_VEHICLE_BATCH_ORDER);
        if (esbSwitch.equals("false")) {
            return ResponseUtil.ok(ReturnResultMsg.getVehicleBatchOrderToSapMsg(vehicleBatchOrderVO.getBstkd()));
        }
        try{
            Map map = HttpUtil.sendPost(vehicleBatchOrder, Constant.SAP_VEHICLE_BATCH_ORDER, Constant.PMS, SAP_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(SAP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag=String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")){//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult=ResponseUtil.fail(Constant.SAP_R_CODE_FAIL,"["+Constant.SAP_VEHICLE_BATCH_ORDER+"]");
            }else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (String.valueOf(jsonResponse.get("code")).equals("E")){
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult=ResponseUtil.fail(Constant.SAP_R_CODE_ERR,"["+Constant.SAP_VEHICLE_BATCH_ORDER+"]"+String.valueOf(jsonResponse.get("zmess")));
                }else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        }catch (Exception e){
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(),e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult=ResponseUtil.fail(Constant.SAP_R_CODE_EXP,"["+Constant.SAP_VEHICLE_BATCH_ORDER+"]");
        }
        //Message message = new Message(rocketConfig.getEaiLogTopic(), "eaiLog",(JSONObject.toJSONString(eaiLog)).getBytes() );
        try {
            //   SendResult send = eaiLogProducer.getProducer().send(message);
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        }catch (Exception e){
            LOGGER.error(e.getMessage(),e);
            apiResult=ResponseUtil.fail(Constant.SAP_R_CODE_EAI,"["+Constant.SAP_VEHICLE_BATCH_ORDER+"]");
        }
        return apiResult;
    }

    @Override
    public ApiResult findPartnerFundBySap(PartnerFundVO partnerFundVO) throws Exception {
        List lists=new ArrayList();
        Map data=new HashMap();
        lists.add(partnerFundVO);
        data.put("lists",lists);
        String partnerFund = JSONObject.toJSONString(data);
        ApiResult apiResult=null;
        EaiLog eaiLog=new EaiLog();
        eaiLog.setPmsEaiContent(partnerFund);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS获取SAP系统渠道资金");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.PMS_SAP_PARTNER_FUND);
        if (esbSwitch.equals("false")) {
            System.out.println("esb没有开启返回默认字段和值");
            return ResponseUtil.ok(ReturnResultMsg.findPartnerFundBySap());
        }
        try{
            Map map = HttpUtil.sendPost(partnerFund, Constant.PMS_SAP_PARTNER_FUND, Constant.PMS, SAP_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(SAP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag=String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")){//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult=ResponseUtil.fail(Constant.SAP_R_CODE_FAIL,"["+Constant.PMS_SAP_PARTNER_FUND+"]【异常】ESB处理失败");
            }else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (String.valueOf(jsonResponse.get("code")).equals("E")){
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult=ResponseUtil.fail(Constant.SAP_R_CODE_ERR,"["+Constant.PMS_SAP_PARTNER_FUND+"]"+String.valueOf(jsonResponse.get("desc")));
                }else {
                    apiResult = ResponseUtil.ok(String.valueOf(jsonResponse.get("return")));
                }
            }
        }catch (Exception e){
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(),e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult=ResponseUtil.fail(Constant.SAP_R_CODE_EXP,"["+Constant.PMS_SAP_PARTNER_FUND+"]【异常】调用ESB接口异常");
        }
        // Message message = new Message(rocketConfig.getEaiLogTopic(), "eaiLog",(JSONObject.toJSONString(eaiLog)).getBytes() );
        try {
            //    SendResult send = eaiLogProducer.getProducer().send(message);
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        }catch (Exception e){
            LOGGER.error(e.getMessage(),e);
            apiResult=ResponseUtil.fail(Constant.SAP_R_CODE_EAI,"["+Constant.PMS_SAP_PARTNER_FUND+"]");
        }
        return apiResult;
    }

    @Override
    public ApiResult findpartnerFundDetailBySap(PartnerFundDetailVO partnerFundDetailVO) throws Exception {
        List lists=new ArrayList();
        Map data=new HashMap();
        lists.add(partnerFundDetailVO);
        data.put("lists",lists);
        String partnerFundDetail = JSONObject.toJSONString(data);
        ApiResult apiResult=null;
        EaiLog eaiLog=new EaiLog();
        eaiLog.setPmsEaiContent(partnerFundDetail);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS获取SAP系统渠道资金明细");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.PMS_SAP_PARTNER_FUND_DETAIL);
        if (esbSwitch.equals("false")) {
            return ResponseUtil.ok(ReturnResultMsg.findpartnerFundDetailBySap());
        }
        try{
            Map map = HttpUtil.sendPost(partnerFundDetail, Constant.PMS_SAP_PARTNER_FUND_DETAIL, Constant.PMS, SAP_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(SAP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag=String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")){//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_FAIL,"["+Constant.PMS_SAP_PARTNER_FUND_DETAIL+"]");
            }else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (String.valueOf(jsonResponse.get("code")).equals("E")){
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_ERR,"["+Constant.PMS_SAP_PARTNER_FUND_DETAIL+"]"+String.valueOf(jsonResponse.get("desc")));
                }else {
                    apiResult = ResponseUtil.ok(String.valueOf(jsonResponse.get("return")));
                }
            }
        }catch (Exception e){
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(),e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EXP,"["+Constant.PMS_SAP_PARTNER_FUND_DETAIL+"]");
        }
        //Message message = new Message(rocketConfig.getEaiLogTopic(), "eaiLog",(JSONObject.toJSONString(eaiLog)).getBytes() );
        try {
            //    SendResult send = eaiLogProducer.getProducer().send(message);
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        }catch (Exception e){
            LOGGER.error(e.getMessage(),e);
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EAI,"["+Constant.PMS_SAP_PARTNER_FUND_DETAIL+"]");
        }
        return apiResult;
    }

    /**
     * 借贷项请求接口
     * @param debitCreditVO
     * @return
     * @throws Exception
     */
    @Override
    public ApiResult sendDebitCreditPms2Sap(DebitCreditVO debitCreditVO) throws Exception {
        String debitCredit = JSONObject.toJSONString(debitCreditVO);
        ApiResult apiResult=null;
        EaiLog eaiLog=new EaiLog();
        eaiLog.setPmsEaiContent(debitCredit);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送借贷项请求信息给SAP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.SAP_DEBIT_CREDIT);
        if (esbSwitch.equals("false")) {
            return ResponseUtil.ok();
        }
        try{
            Map map = HttpUtil.sendPost(debitCredit, Constant.SAP_DEBIT_CREDIT, Constant.PMS, SAP_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(SAP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag=String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")){//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_FAIL,"["+Constant.SAP_DEBIT_CREDIT+"]");
            }else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (String.valueOf(jsonResponse.get("code")).equals("E")){
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_ERR,"["+Constant.SAP_DEBIT_CREDIT+"]"+String.valueOf(jsonResponse.get("zmess")));
                }else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        }catch (Exception e){
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(),e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EXP,"["+Constant.SAP_DEBIT_CREDIT+"]");
        }
        try {
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        }catch (Exception e){
            LOGGER.error(e.getMessage(),e);
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EAI,"["+Constant.SAP_DEBIT_CREDIT+"]");
        }
        return apiResult;
    }

    /**
     * 返利发放金额同步接口
     * @param rebateAmountVO
     * @return
     * @throws Exception
     */
    @Override
    public ApiResult sendRebateAmountPms2Sap(RebateAmountVO rebateAmountVO) throws Exception {
        String rebateAmount = JSONObject.toJSONString(rebateAmountVO);
        ApiResult apiResult=null;
        EaiLog eaiLog=new EaiLog();
        eaiLog.setPmsEaiContent(rebateAmount);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送返利发放金额同步信息给SAP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.SAP_REBATE_AMOUNT);
        //SAP返利状态，后期触发
        eaiLog.setDisposeStatus(4);
        apiResult=ResponseUtil.ok();
        if (esbSwitch.equals("false")) {
            return ResponseUtil.ok();
        }
        try{
        /*    Map map = HttpUtil.sendPost(rebateAmount, Constant.SAP_REBATE_AMOUNT, Constant.PMS, SAP_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(SAP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag=String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")){//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult=ResponseUtil.fail();
            }else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (String.valueOf(jsonResponse.get("code")).equals("E")){
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult=ResponseUtil.fail();
                }else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }*/
        }catch (Exception e){
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(),e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EXP,"["+Constant.SAP_REBATE_AMOUNT+"]");
        }
        try {
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        }catch (Exception e){
            LOGGER.error(e.getMessage(),e);
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EAI,"["+Constant.SAP_REBATE_AMOUNT+"]");
        }
        return apiResult;
    }

    /**
     * 批售订单修改
     * @param vehicleBatchOrderModifyVO
     * @return
     * @throws Exception
     */
    @Override
    public ApiResult sendVehicleBatchOrderModifyPms2Sap(VehicleBatchOrderModifyVO vehicleBatchOrderModifyVO) throws Exception {
        String vehicleBatchOrder = JSONObject.toJSONString(vehicleBatchOrderModifyVO);
        ApiResult apiResult=null;
        EaiLog eaiLog=new EaiLog();
        eaiLog.setPmsEaiContent(vehicleBatchOrder);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送整车批售订单修改信息给SAP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.SAP_VEHICLE_BATCH_ORDER_MODIFY);
        if (esbSwitch.equals("false")) {
            return ResponseUtil.ok(ReturnResultMsg.sendVehicleBatchOrderModifyPms2Sap());
        }
        try{
            Map map = HttpUtil.sendPost(vehicleBatchOrder, Constant.SAP_VEHICLE_BATCH_ORDER_MODIFY, Constant.PMS, SAP_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(SAP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag=String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")){//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_FAIL,"["+Constant.SAP_VEHICLE_BATCH_ORDER_MODIFY+"]");
            }else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (String.valueOf(jsonResponse.get("code")).equals("E")){
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_ERR,"["+Constant.SAP_VEHICLE_BATCH_ORDER_MODIFY+"]"+String.valueOf(jsonResponse.get("zmess")));
                }else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        }catch (Exception e){
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(),e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EXP,"["+Constant.SAP_VEHICLE_BATCH_ORDER_MODIFY+"]");
        }
        try {
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        }catch (Exception e){
            LOGGER.error(e.getMessage(),e);
            apiResult = ResponseUtil.fail(Constant.SAP_R_CODE_EAI,"["+Constant.SAP_VEHICLE_BATCH_ORDER_MODIFY+"]");
        }
        return apiResult;
    }




}
